package com.wkbb.common.business;

import com.wkbb.common.constants.RedisKeyConstant;
import com.wkbb.common.dto.basic.NickNameDto;
import com.wkbb.common.enums.RoleTypeEnum;
import com.wkbb.common.redis.RedisTemplateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Alger Yang
 * @title: BasicBusiness
 * @projectName wkbb-3.0
 * @description: basic模块公共业务
 * @date 2019/7/30 003016:25
 */
public class BasicBusiness {

    private static final Logger logger = LoggerFactory.getLogger(BasicBusiness.class);

    public static NickNameDto getRedisNickname(RedisTemplateUtil redisTemplateUtil, NickNameDto nickNameDto) {
        String key = getNickNameRedisKey(nickNameDto);
        return (NickNameDto) redisTemplateUtil.get(key);
    }

    public static String getNickNameRedisKey(NickNameDto nickNameDto) {
        String fix = "";
        //删除情况下就不关注下面的内容
            fix += ":roleType_" + nickNameDto.getRoleType();
            if (nickNameDto.getRoleType() == RoleTypeEnum.FAMILY.getValue()) {
                fix += ":classId_" + (nickNameDto.getClassId() == null ? "0" : nickNameDto.getClassId())
                        + ":studentId_" + (nickNameDto.getStudentId() == null ? "0" : nickNameDto.getStudentId());
            }

        return RedisKeyConstant.WKBB_BASIC_USER_FRONT + "nickName"+
                ":userId_" + nickNameDto.getUserId() +
                ":orgId_" +  nickNameDto.getOrgId() +
                fix + ":";
    }
    public static String getNickNameSetRedisKey(NickNameDto nickNameDto) {
        return RedisKeyConstant.WKBB_BASIC_USER_FRONT + "nickNameSet"+
                ":userId_" + nickNameDto.getUserId()  ;
    }

    /**
     * 组织缓存
     */
    public static String getOrganizationRedisKey(Long id) {
        return RedisKeyConstant.ORGANIZATION + "orgId_" + id + ":";
    }

    /**
     * 组织缓存
     */
    public static String getSmartOrganizationRedisKey(String smartOrgId) {
        return RedisKeyConstant.ORGANIZATION + "smartOrgId_" + smartOrgId + ":";
    }

    /**
     * 年级缓存
     */
    public static String getGradeRedisKey(Long id) {
        return RedisKeyConstant.GRADE + "gradeId_" + (id == null ? "*" : id) + ":";
    }

    /**
     * 班级缓存
     */
    public static String getClassRedisKey(Long id) {
        return RedisKeyConstant.CLASSINFO + "classId_" + id + ":";
    }

    /**
     * 盒子缓存
     */
    public static String getBoxRedisKey(String uuid, String id) {
        return RedisKeyConstant.WKBB_BASIC_DEVICE_BOX + "uuid_" + uuid + ":id_" + id + ":";
    }

    /**
     * IPC缓存
     */
    public static String getIpcRedisKey(String uuid, String id) {
        return RedisKeyConstant.WKBB_BASIC_DEVICE_IPC + "uuid_" + uuid + ":id_" + id + ":";
    }

    /**
     * 设备通信协议缓存
     */
    public static String getDeviceProtocalRedisKey(String deviceCode) {
        return RedisKeyConstant.WKBB_BASIC_DEVICE_PROTOCAL + "deviceCode_" + deviceCode + ":";
    }

    /**
     * 设备缓存
     */
    public static String getDeviceInfoRedisKey(String deviceCode) {
        return RedisKeyConstant.WKBB_BASIC_DEVICE_INFO + "deviceCode_" + deviceCode;
    }
}
